import {createApp} from 'vue'
import App from './App.vue'
import Antd, {message, Modal} from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import router from './route/index'
import {baseURL, http} from './http'
import util from './util'
import constant from './constant'
import Crud from '@/components/Crud.vue'
import RemoteSelect from '@/components/RemoteSelect.vue'
import Upload from '@/components/Upload.vue'
import FullEditor from '@/components/FullEditor.vue'
import DatePicker from '@/components/DatePicker.vue'
import YesOrNo from '@/components/YesOrNo.vue'
import Select from '@/components/Select.vue'
import MapSelect from '@/components/MapSelect.vue'
import CheckBox from '@/components/CheckBox.vue'

const app = createApp(App)
app.config.globalProperties.post = (url, data) => http('post', url, data)
app.config.globalProperties.get = (url, data) => http('get', url, data)
app.config.globalProperties.success = (msg = '成功！', duration = 1.2) => message.success(msg, duration)
app.config.globalProperties.error = (msg = '失败！', duration = 1.5) => message.error(msg, duration)
app.config.globalProperties.loading = (msg = '加载中...', duration = 1.2) => {
	const hide = message.loading(msg, duration);
	setTimeout(hide, duration)
}
app.config.globalProperties.util = util
app.config.globalProperties.baseURL = baseURL
app.config.globalProperties.constant = constant

app.component('Crud', Crud)
app.component('RemoteSelect', RemoteSelect)
app.component('Upload', Upload)
app.component('FullEditor', FullEditor)
app.component('DatePicker', DatePicker)
app.component('YesOrNo', YesOrNo)
app.component('Select', Select)
app.component('MapSelect', MapSelect)
app.component('CheckBox', CheckBox)
app.config.globalProperties.formatTime = (time) => {
	// let date = new Date(time);
	let date = new Date(time * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
	let YYYY = date.getFullYear();
	let MM = date.getMonth() + 1;
	let DD = date.getDate();
	let hh = date.getHours();
	let mm = date.getMinutes();
	let ss = date.getSeconds();

	MM = MM < 10 ? ('0' + MM) : MM;
	DD = DD < 10 ? ('0' + DD) : DD;
	hh = hh < 10 ? ('0' + hh) : hh;
	mm = mm < 10 ? ('0' + mm) : mm;
	ss = ss < 10 ? ('0' + ss) : ss;

	return YYYY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
}
app.config.globalProperties.imgPreview = (img) => {
	const modal = Modal.success({
		title: `${img}`,
		content: `${img}`,
	});
}


app.use(Antd)
app.use(router)

app.mount('#app')
